#include "stdafx.h"

#define DOTNET

#include "RayTracer/RayTracer.h"

#include "TracerLib.h"

namespace TracerLib {

	Tracer::Tracer() : _tracer(new RayTracer())
	{
	}

	Tracer::~Tracer()
	{
		delete _tracer;
	}

	std::string ToStd(System::String ^inpString)
	{
		using namespace Runtime::InteropServices;
		
		const char* chars = 
			(const char*)(Marshal::StringToHGlobalAnsi(inpString)).ToPointer();
		std::string returnString(chars);
		Marshal::FreeHGlobal(IntPtr((void*)chars));
		return returnString;
	}

	System::Void Tracer::Save(System::String^ fileName)
	{
		_tracer->SaveImage(ToStd(fileName));
	}

	System::String^ ToDotNet(const std::string& inp)
	{
		return gcnew String(inp.c_str());
	}

	System::String^ Tracer::Draw(unsigned width, unsigned height, System::String^ defention)
	{
		return ToDotNet(_tracer->DrawImage(width, height, _counter = new unsigned(0), ToStd(defention)));
	}

	unsigned Tracer::GetCount()
	{
		return *_counter;
	}
}
